package com.hdsx.restful.glzt.structure.jpjg.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.esri.arcgis.geometry.IGeometry;
import com.hdsx.ao.base.BaseOpearte;
import com.hdsx.restful.glzt.structure.jpjg.bean.Jpjg;
import com.hdsx.restful.glzt.structure.jpjg.mapper.JpjgMapper;
import com.hdsx.restful.glzt.structure.jpjg.service.JpjgServer;
import com.hdsx.restful.glzt.structure.ql.bean.IntValueName;
import com.hdsx.restful.glzt.structure.ql.bean.StatisticalResult;
import com.hdsx.restful.util.Dao;
/**
 * jpjgServer实现类
 *
 */
@Service
public class JpjgServerImpl extends BaseOpearte<Jpjg> implements JpjgServer {

	public JpjgServerImpl() {
		super("GIS_JPJG");
	}

	@Resource(name="jpjgMapper")
	private JpjgMapper mapper;

	@Override
	public List<Jpjg> getList(Map<String, Object> parameter) {
		return mapper.queryList(parameter);
	}

	@Override
	public Jpjg getById(String id) {
		return mapper.queryOne(id);
	}

	@Override
	public boolean addJpjg(Jpjg jpjg) {
		return mapper.add(jpjg)>0;
	}

	@Override
	public boolean updateJpjg(Jpjg jpjg) {
		return mapper.update(jpjg)>0;
	}

	@Override
	public boolean deleteById(String id) {
		return mapper.delete(id)>0;
	}

	@Override
	public int queryJpjgCountBylxdh(String jgmc) {
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("jgmc", jgmc);
		return mapper.countByLxbm(parameter);
	}

	@Override
	public List<Jpjg> getListBylxdh(String jgmc, int begin, int end) {
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("jgmc", jgmc);
		parameter.put("begin", begin);
		parameter.put("end", end);
		return mapper.selectListByLxbm(parameter);
	}

	@Override
	public int queryJpjgCountXzqhbm(String xzqhbm,String jyyhmc) {
		if(xzqhbm!=null){
			if(xzqhbm.endsWith("0000")){
				xzqhbm=xzqhbm.substring(0,2);
			}else if(xzqhbm.endsWith("00")){
				xzqhbm=xzqhbm.substring(0,4);
			}
		}
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("xzqhbm", xzqhbm);
		parameter.put("jyyhmc", jyyhmc);
		return mapper.countByXzqhbm(parameter);
	}

	@Override
	public List<Jpjg> getListByXzqhbm(String xzqhbm,String jyyhmc, int begin, int end) {
				if(xzqhbm!=null){
					if(xzqhbm.endsWith("0000")){
						xzqhbm=xzqhbm.substring(0,2);
					}else if(xzqhbm.endsWith("00")){
						xzqhbm=xzqhbm.substring(0,4);
					}
				}
				Map<String,Object> parameter=new HashMap<String,Object>();
				parameter.put("xzqhbm", xzqhbm);
				parameter.put("jyyhmc", jyyhmc);
				parameter.put("begin", begin);
				parameter.put("end", end);
				return mapper.selectListByXzqhbm(parameter);
	}

	@Override
	public int queryJpjgCount(String name, String xzqhbm) {
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("name", name);
		parameter.put("xzqubm", xzqhbm);
		return mapper.countAll(parameter);
	}

	@Override
	public List<Jpjg> getList(String xzqhbm, String name, int begin, int end) {
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("name", name);
		parameter.put("xzqubm", xzqhbm);
		parameter.put("begin", begin);
		parameter.put("end", end);
		List<Jpjg> lists= mapper.selectList(parameter);
		return lists;
	}

	@Override
	public Jpjg getOne(String jyyhxkzbh) {
		return mapper.queryOne(jyyhxkzbh);
	}

	@Override
	public List<Dao> getShapeById(String id) {
		Jpjg bean = mapper.getShapeById(id);
		IGeometry shape=selectShape("ID='"+id+"'");
		bean.setShape(shape);
		List<Dao> list=new ArrayList<Dao>();
		list.add(new Dao("经营业户名称",bean.getJyyhmc(),bean.getPtx(),bean.getPty()));
		list.add(new Dao("经营许可证号",bean.getJyyhxkzbh()));
		list.add(new Dao("行政区划",bean.getXzqhbm()));
		list.add(new Dao("驾校级别",bean.getJgjb()));
		list.add(new Dao("驾校规模",bean.getGm()));
		list.add(new Dao("信誉考核结果",bean.getXykhjg()));
		return list;
	}
	
	@Override
	public StatisticalResult countByParameter(Map<String,Object> map) {
		List<IntValueName> seriesData = mapper.countTotalByParameter(map);
		List<String> legendData = mapper.selectClassify(map);
		StatisticalResult sr = new StatisticalResult();
		sr.setChartsText("驾培机构统计");
		sr.setSeriesData(seriesData);
		sr.setLegendData(legendData);
		return sr;
	}
	
	@Override
	public List<String> selectName(String name){
		return mapper.selectName(name);
	}
}
